﻿using System;
using System.Linq.Expressions;

namespace Alex.Library.Specifications
{
    /// <summary>
    /// invert the specification
    /// </summary>
    /// <typeparam name="T">any type</typeparam>
    public sealed class NotSpecification<T> : Specification<T>
    {
        private ISpecification<T> spec;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="specification">any specification</param>
        public NotSpecification(ISpecification<T> specification)
        {
            this.spec = specification;    
        }

        /// <summary>
        /// get lambda expression's body
        /// </summary>
        /// <returns>lambda expression's body</returns>
        public override Expression<Func<T, bool>> GetExpression()
        {
            return this.spec.GetExpression().Not();
        }
    }
}
